﻿@model Winner.Game.Entity.ViewModel.UserInfoEditViewModel

@{
    ViewBag.Title = "Edit";
}



@using (Html.BeginForm("Edit", "UserInfo", FormMethod.Post, new { id = "from_UserInfo" }))
{

    <fieldset>
        <legend>会员基本信息</legend>
        <table align="center">
            <tr>
                <td>会员编号：</td>
                <td>@Html.EditorFor(model => model.UserID)</td>

            </tr>
            <tr>
                <td>会员姓名：</td>
                <td>@Html.EditorFor(model => model.UserName)</td>
            </tr>
            <tr>
                <td>会员登录名：</td>
                <td>@Html.EditorFor(model => model.LoginName)</td>
            </tr>
            <tr>
                <td>会员密码：</td>
                <td>@Html.PasswordFor(model => model.UserPassword)</td>
            </tr>
            <tr>
                <td>会员性别：</td>
                <td>
                    @Html.RadioButtonFor(model => model.UserSex, "1", new { @checked = "checked" })男
                    @Html.RadioButtonFor(model => model.UserSex, "2")女
                </td>
            </tr>
            <tr>
                <td>联系方式：</td>
                <td>@Html.EditorFor(model => model.UserPhone)</td>
            </tr>
            <tr>
                <td>电子邮箱：</td>
                <td>@Html.EditorFor(model => model.UserEmail)</td>
            </tr>
            <tr>
                <td>会员等级：</td>
                <td>
                    @Html.DropDownListFor(model => model.UserLevel, ViewBag.UserLevelList as IEnumerable<SelectListItem>)
                </td>
            </tr>
            <tr>
                <td>会员积分：</td>
                <td>@Html.EditorFor(model => model.UserPoint)</td>
            </tr>
            <tr>
                <td>会员状态：</td>
                <td>
                    @Html.RadioButtonFor(model => model.UserState, "1", new { @checked = "checked" })在线
                    @Html.RadioButtonFor(model => model.UserState, "2")忙碌
                    @Html.RadioButtonFor(model => model.UserState, "3")离线

                </td>
            </tr>
            <tr>

                <td></td>
                <td><input type="button" id="btn_Submit" value="提交" /></td>
                <td> </td>
            </tr>
        </table>

        @Html.HiddenFor(model => model.ID)
    </fieldset>


    <script>
        $('#btn_Submit').click(function () {

            //赋值一个动态变量，能够更改Url
            var postUrl = "";

            //根据隐藏域的ID值来判断是添加还是编辑
            //parseInt 转值整数 parseFloat 转值小数
            if (parseInt($("#ID").val()) > 0)
            {
                postUrl = "/UserInfo/Edit";
            }
            else
            {
                postUrl = "/UserInfo/Add";
            };

            //ajax表单提交
            $('#from_UserInfo').form('submit', {
                url: postUrl,
                onSubmit: function () {
                    //var isValid = $(this).form('validate');
                    //return isValid;//返回false终止表单提交
                },
                success: function (data) {
                    //这里data是一个字符串！！！不是Json对象！！！
                    //需要把字符串转化成Json对象

                    var json = JSON.parse(data);
                    if (json.State == 1)
                    {
                        //1.提示消息
                        window.parent.$.messager.alert('温馨提示', json.Message, 'info');

                        //2.关闭弹窗(父子结构，两级信息传递)
                        window.parent.$("#dlg").dialog("close");

                        //3.刷新列表
                        window.parent.$("#dg_User").datagrid('reload');
                    }
                    else
                    {
                        $.messager.alert('温馨提示', json.Message, 'info');
                    }


                }
            });
        });


    </script>
}